<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<!-- Standard Head Part -->
<head>
<title>NUnit - TestCaseFactory</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-US">
<link rel="stylesheet" type="text/css" href="nunit.css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<!-- End Standard Head Part -->

<body>

<!-- Standard Header for NUnit.org -->
<div id="header">
  <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
  <div id="nav">
    <a href="http://www.nunit.org">NUnit</a>
    <a class="active" href="index.html">Documentation</a>
  </div>
</div>
<!-- End of Header -->

<div id="content">

<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->

<h3>TestCaseFactoryAttribute (NUnit 2.5)</h3>

<div style="text-align: center; margin: 2em 10%; padding: 4px 0; border: 2px solid black">
  <h4>Preliminary documentation, subject to change.</h4>
</div>

<p>TestCaseFactoryAttribute may be used to mark a field, property or method that
is intended for use as a source of test case parameters. It's use is optional
if the test factory is always referenced by name but required if it is to be
located automatically by NUnit.

<p>The attribute takes a list of Types as an argument and indicates that the
field, property or method to which it is applied returns sets of arguments
of the types specified. NUnit uses this information to determine if the
test case factory is compatible with any given method.

<h4>Example</h4>

<div class="code">
<pre>[TestFixture]
public class MyTests
{
  [Test,Factory(typeof(MyFactoryClass)]
  public void DivideTest(int n, int d, int q)
  {
    Assert.AreEqual( q, n / d );
  }
	
  ...
}

public class MyFactoryClass
{
  [TestCaseFactory(typeof(int), typeof(int))]
  public static IEnumerable TestCases
  {
    get
    {
      yield return new TestCaseData( 12, 3 ).Returns( 4 );
      yield return new TestCaseData( 12, 2 ).Returns( 6 );
      yield return new TestCaseData( 12, 4 ).Returns( 3 );
      yield return new TestCaseData( 0, 0 )
        .Throws(typeof(DivideByZeroException))
        .With.TestName("DivideByZero")
        .With.Description("An exception is expected");
    }
  }  
}
</div>

</div>

<!-- Submenu -->
<div id="subnav">
<ul>
<li><a href="index.html">NUnit 2.5</a></li>
<ul>
<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
<li><a href="assertions.html">Assertions</a></li>
<li><a href="attributes.html">Attributes</a></li>
<ul>
<li><a href="testIdentification.html">Test&nbsp;Identification</a></li>
<li><a href="testSelection.html">Test&nbsp;Selection</a></li>
<li><a href="testModification.html">Test&nbsp;Modification</a></li>
<li><a href="setupTeardown.html">Setup&nbsp;and&nbsp;Teardown</a></li>
<li><a href="parameterizedTests.html">Parameterized&nbsp;Tests</a></li>
<ul>
<li><a href="combinatorial.html">Combinatorial</a></li>
<li><a href="factory.html">Factory</a></li>
<li><a href="pairwise.html">Pairwise</a></li>
<li><a href="random.html">Random</a></li>
<li><a href="range.html">Range</a></li>
<li><a href="sequential.html">Sequential</a></li>
<li><a href="testCase.html">Test&nbsp;Case</a></li>
<li id="current"><a href="testCaseFactory.html">Test&nbsp;Case&nbsp;Factory</a></li>
<li><a href="values.html">Values</a></li>
</ul>
</ul>
<li><a href="nunit-console.html">Console&nbsp;Runner</a></li>
<li><a href="nunit-gui.html">Gui&nbsp;Runner</a></li>
<li><a href="features.html">Other&nbsp;Features</a></li>
<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
<li><a href="samples.html">Samples</a></li>
<li><a href="license.html">License</a></li>
</ul>
</ul>
</div>
<!-- End of Submenu -->


<!-- Standard Footer for NUnit.org -->
<div id="footer">
  Copyright &copy; 2008 Charlie Poole. All Rights Reserved.
</div>
<!-- End of Footer -->

</body>
</html>
